#include <sys/stat.h>
#include <unistd.h>
#include <fstream>
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <SDL2/SDL.h>
#include "det_platform.h"

// 检测是否是 RK35xx 平台
bool is_rk35xx() 
{
    std::ifstream cpuinfo("/proc/cpuinfo");
    std::string line;
    while (std::getline(cpuinfo, line)) {
        if (line.find("Processor") != std::string::npos || line.find("model name") != std::string::npos) {
            if (line.find("Rockchip RK35") != std::string::npos) {
                return true;
            }
        }
    }
    return false;
}

// 检测是否存在 GPU 设备（如 /dev/dri/card0）
bool has_gpu_device() 
{
    DIR *dir = opendir("/dev/dri/");
    if (!dir) return false;

    struct dirent *entry;
    while ((entry = readdir(dir))) {
        if (strncmp(entry->d_name, "card", 4) == 0) {
            closedir(dir);
            return true;
        }
    }
    closedir(dir);
    return false;
}

// 使用 SDL 检测是否有硬件加速能力
bool is_hardware_renderer(SDL_Renderer *renderer) 
{
    SDL_RendererInfo info;
    SDL_GetRendererInfo(renderer, &info);
    return (info.flags & SDL_RENDERER_ACCELERATED) != 0;
}